package com.alan.designMode.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * Created by Alan on 17-8-29
 */
public class Client {

    public static void main(String[] args) {
        //静态代理与强制代理
//        IGamePlayer player = new GamePlayer("test");
//        IGamePlayer proxy = player.getProxy();
//        proxy.login("test","test");
//        proxy.killBoss();
//        proxy.upgrade();
        //动态代理
        IGamePlayer2 player = new GamePlayer2("test");
        InvocationHandler handler = new GamePlayIH(player);
        //获得类的class loader
        ClassLoader cl = player.getClass().getClassLoader();
        //动态产生一个代理
        IGamePlayer2 proxy = (IGamePlayer2) Proxy.newProxyInstance(cl,new Class[]{IGamePlayer2.class},handler);
        proxy.login("test","test");
        proxy.killBoss();
        proxy.upgrade();



    }

}
